import jwt from "jsonwebtoken"
import wechatService from "../service/wechat.service.js"
const { getWxtokenService } = wechatService

class WechatController {
  // 获取微信小程序 Token
  async getWxToken(ctx, next) {
    const { js_code } = ctx.request.body
    try {
      const data = await getWxtokenService({ js_code })
      ctx.echo({
        token: jwt.sign(data, process.env.JWT_SECRET, { expiresIn: "1d" }),
      })
    } catch (error) {
      console.error(error)
    }
  }
}

export default new WechatController()
